<?php
header("Content-Type:text/html;charset=UTF-8");
include "db.php";

function sn1($table, $field, $prefix)
	{
		$billno = date('YmdHis') . strrandom(6,1);

		while (1) {
			$count = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_' . $table) . ' where ' . $field . '=:billno limit 1', array(':billno' => $billno));

			if ($count <= 0) {
				break;
			}

			$billno = date('YmdHis') .strrandom(6,1);
		}

		return $prefix . $billno;
	}
	
	
	for($i=1;$i<=1000;$i++){
	$arr[] = sn1('order','ordersn','KK');
	
	}
	if (count($arr) != count(array_unique($arr))) {   
   echo '该数组有重复值';  
}else{
echo "没有重复";
}
	//dump($arr);